<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>16_jQuery-attr基本操作</title>
</head>
<body>
  
  <ul id="list" name="attr" age="17">
    <li class="li-1">li-1</li>
    <li class="li-2">li-2</li>
    <li class="li-3">li-3</li>
    <li class="li-4">li-4</li>
    <li class="li-5">li-5</li>
  </ul>

  <script src="../libs/jquery-3.6.0.js"></script>
  <script>

    $(function () {
      // 1. 获取属性值
      console.log($('#list').attr('name'));
      console.log($('#list').attr('age'));

      // 2. 设置属性值
      $('#list').attr('name', 'newName');
      $('#list').attr('age', '18');
      $('#list').attr({
        name: 'newName',
        age: '18'
      })

      // 3. 删除属性
      $('#list').removeAttr('age');
    })

  </script>

</body>
</html>